<template>
  <el-dialog
    width="70%"
    title="选择合同物资"
    @opened="getList"
    :visible.sync="hideDilog"
    :before-close="cance"
  >
    <div class="ccui-multifunctional-table-wrapper">
      <ux-grid
        ref="multipleTable"
        :data="tableData"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        border
        v-loading="dialogLoading"
        max-height="400"
      >
        <ux-table-column type="checkbox" width="55" fixed="left" />
        <ux-table-column title="序号" type="index" width="80" fixed="left" />
        <ux-table-column
          :show-overflow-tooltip="true"
          fixed="left"
          field="materialsCode"
          title="设备物资编码"
          width="200"
        >
        </ux-table-column>
        <ux-table-column
          fixed="left"
          :show-overflow-tooltip="true"
          field="materialsName"
          width="300"
          title="设备物资名称"
        >
        </ux-table-column>

        <ux-table-column
          :show-overflow-tooltip="true"
          field="matDescribe"
          title="设备物资说明"
          width="130"
        >
        </ux-table-column>
        <ux-table-column
          :show-overflow-tooltip="true"
          field="thirdCategoriesOfName"
          title="分类名称"
          width="130"
        >
        </ux-table-column>

        <ux-table-column
          :show-overflow-tooltip="true"
          field="currentMeasuringUnit"
          width="90"
          title="计量单位"
        >
        </ux-table-column>
        <ux-table-column
          :show-overflow-tooltip="true"
          field="currentNum"
          title="数量"
          :formatter="numFormatter"
          width="80"
        >
        </ux-table-column>

        <ux-table-column
          :show-overflow-tooltip="true"
          width="130"
          field="currentUnitPriceIncludeTax"
          :formatter="priceDjFormatter"
          title="含税单价"
        >
        </ux-table-column>
        <ux-table-column
          width="130"
          :show-overflow-tooltip="true"
          field="currentChangeAmtIncludeTax"
          :formatter="priceFormatter"
          title="含税金额"
        >
        </ux-table-column>
        <ux-table-column
          width="130"
          :show-overflow-tooltip="true"
          field="taxRatePercent"
          title="税率"
        >
        </ux-table-column>
        <ux-table-column
          width="130"
          :show-overflow-tooltip="true"
          field="rate"
          :formatter="rateFormatter"
          title="税额"
        >
        </ux-table-column>

        <ux-table-column
          :show-overflow-tooltip="true"
          field="testdaohuo"
          width="200"
          title="交货地点"
        >
        </ux-table-column>
        <ux-table-column
          :show-overflow-tooltip="true"
          width="170"
          field="deliveryTime"
          :formatter="formatterDate"
          title="交货时间"
          formea
        >
        </ux-table-column>
        <ux-table-column
          :show-overflow-tooltip="true"
          field="manufacturer"
          title="生产厂家/品牌"
          width="200"
        >
        </ux-table-column>
      </ux-grid>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cance">取 消</el-button>
      <el-button type="primary" @click="confirm">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { getSmpPcConcMatListById } from "../api/index";
import { formatNumber } from "@/basa/utils";
export default {
  props: {
    hideDilog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      checkedArr: null,
      tableData: [],
      dialogLoading: false
    };
  },
  computed: {
    contractId() {
      return this.$store.state.equipmentYanshou.contractId;
    }
  },
  methods: {
    getList() {
      this.dialogLoading = true;
      getSmpPcConcMatListById({
        concId: this.contractId * 1
        // concId: 129
      }).then(res => {
        const { data } = res.data;
        data.forEach(item => {
          // 验收地点
          item.testdaohuo =
            item.deliveryAreaName +
            item.provinceName +
            item.cityName +
            item.countyName +
            item.deliveryPoints;
        });
        this.tableData = data;
        this.dialogLoading = false;
      });
    },

    cance() {
      this.$emit("update:hideDilog", false);
    },
    handleSelectionChange(val) {
      this.checkedArr = val;
    },
    // 确定按钮
    confirm() {
      if (!this.checkedArr) {
        this.$message.warning("请选择一项");
        return;
      }
      this.$emit("materialArr", this.checkedArr);
      this.$emit("update:hideDilog", false);
      this.$refs.multipleTable.clearSelection();
    },
    fiters(item) {
      let title = this.$route.query.title;
      let materialId = null;

      switch (title) {
        case "按合同验收":
          materialId = item.id;
          break;
        case "按订单验收":
          materialId = item.id;
          break;
        case "按发货单验收":
          materialId = item.id;
          break;
      }
      return materialId;
    },
    numFormatter({ row }) {
      return formatNumber(row.currentNum, 3);
    },
    priceDjFormatter({ row }) {
      return row.currentUnitPriceIncludeTax
        ? row.currentUnitPriceIncludeTax.toFixed(2)
        : row.currentUnitPriceIncludeTax;
    },
    priceFormatter({ row }) {
      return row.currentChangeAmtIncludeTax
        ? row.currentChangeAmtIncludeTax.toFixed(2)
        : row.currentChangeAmtIncludeTax;
    },
    shuilvFormatter({ row }) {
      return row.taxRatePercent + "%";
    },
    rateFormatter({ row }) {
      return row.rate ? row.rate.toFixed(2) : row.rate;
    },
    formatterDate({ row }) {
      if (row.deliveryTime) {
        return row.deliveryTime.split(" ")[0];
      }
    }
  }
};
</script>
